#include "head.h"

#define DEBUG 0
#if DEBUG
#endif

#if 1
int disp_jpeg_up(char *filename)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t * scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i, j;
	for(i = 0; i < my_fb.h; ++i){
		for (j = 0; j < my_fb.w; ++j){
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
		}
		usleep(10000);
	}
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}

#if 1
int disp_jpeg_down(char *filename)
{	
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24,my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i, j, z;
	for(z = 0; z <= my_fb.h; z--)
	{
		for(i = 0; i < my_fb.h; ++i){
			for (j = 0; j < my_fb.w; ++j)
			{       
				if((j >= 0 && j <= my_fb.w) && (i >= (my_fb.h - z) && i <= my_fb.h))
					fb_pixel(j, i, buf32[j + i * my_fb.w]);
			}

		}
		z = z + 3;
		usleep(1000);
	}
	usleep(500000); 
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}
#endif

#if 1
int disp_jpeg_c(char *filename,int x,int y,int len)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24,my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i,j,z;

	for(z = len; z < my_fb.w; z++)
	{
		for(i = 0; i < my_fb.h; i++)
			for(j = 0; j < my_fb.w; j++)
			{
				if((i - x) * (i - x) + (j - y) * (j - y) <= z * z)
					fb_pixel(j, i, buf32[j + i * my_fb.w]);
			}
		usleep(5);
		z = z + 3;
	}
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}
#endif 

#if 1
int disp_jpeg_d(char *filename,int x,int y,int len)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24,my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i, j, z;

	for(z = 700; z >= len; z--)
	{
		for(i = 0; i < my_fb.h; i++)
			for(j = 0; j < my_fb.w; j++)
			{
				if(!((i - x) * (i - x) + (j - y) * (j - y) <= z * z))
					fb_pixel(j, i, buf32[ j + i * my_fb.w]);
			}
		usleep(10);
		z = z - 1;
	}
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}
#endif

#if 0
int disp_jpeg_1(char *filename)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i, j, z;
	for(z = 0; z < 799; z++)
	{
		for(i = 0; i < z; i++)
			for(j = 0; j < z + 480; j++)
				fb_pixel(j, i, buf32[j + i * my_fb.w]);

		usleep(100);
		z = z + 3;
	}
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}
#endif

#if 1
int disp_jpeg_2(char *filename)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24,my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i, j, z;
	for(z = 0; z < my_fb.w; z++)
	{
		for(i = 0; i < my_fb.h; i++)
			for(j = 0; j < my_fb.w; j++)
			{     
				if((i >= (my_fb.h - z + (my_fb.w - my_fb.h)) && i <= my_fb.h) && (j >= (my_fb.w - z) && j < my_fb.w))
				{

					fb_pixel(j, i, buf32[j + i * my_fb.w]);
				}
			}
		usleep(100);
		z = z + 1;
	}
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}
#endif

int disp_jpeg_right(char * filename)
{	
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0, j = 0;
	system("clear");
	for(i = my_fb.w; i > 0; i--)
	{
		for(j = 0; j < my_fb.h ; j++)
			fb_pixel(i, j, buf32[i + j * my_fb.w] );

		usleep(10000);
	}
	printf("i = %d j = %d\n", i, j);
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}

int disp_jpeg_left(char *filename)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0; 
	int j = 0;

	system("clear");
	for(i = 0; i < my_fb.w; i++)
	{
		for(j = 0; j < my_fb.h; j++)
			fb_pixel(i, j, buf32[i + j * my_fb.w]);

		usleep(10000);
	}

	printf("i = %d j = %d\n", i, j);
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);


	return 0;
}
#if 1
int disp_jpeg_to_middle(char *filename)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;
	system("clear");

	for(i = 0; i < my_fb.h / 2; i++)
	{
		for(j = 0; j < my_fb.w; j++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(j, my_fb.h - i - 1, buf32[j + (my_fb.h - i - 1) * my_fb.w]);
		}
		usleep(10000);
	}
	printf("i = %d  j = %d\n", i, j);
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}
#endif

int disp_jpeg_middle_to(char *filename)
{	
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int  i = my_fb.h / 2;
	int j = 0;
	for(; i > 0; i--)
	{
		for(j = 0; j < my_fb.w; j++)
		{	
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(j, my_fb.h - i, buf32[j + (my_fb.h - i) * my_fb.w]);
		}
		usleep(10000);
	}
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}

int disp_jpeg_middle_side(char *filename)
{	
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int  i = my_fb.w / 2;
	int j = 0;
	for(; i > 0; i--)
	{
		for(j = 0; j < my_fb.h; j++)
		{	
			fb_pixel(i, j, buf32[i + j * my_fb.w]);
			fb_pixel(my_fb.w - i, j, buf32[my_fb.w - i + (j * my_fb.w)]);
		}
		usleep(10000);
	}
	usleep(500000);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}

#if 1
int disp_jpeg_center(char *filename)
{	
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;

	for(i = 0; i < my_fb.h / 2; i++)
	{
		for(j = 0; j < my_fb.w / 2; j++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(j + my_fb.w / 2, i + my_fb.h / 2, buf32[(j + my_fb.w / 2) + (i + my_fb.h / 2) * my_fb.w]);
			fb_pixel(j, my_fb.h - i - 1, buf32[j + (my_fb.h - i - 1) * my_fb.w]);
			fb_pixel(j + my_fb.w / 2, my_fb.h / 2 - i, buf32[j + my_fb.w / 2 + (my_fb.h / 2 - i) * my_fb.w]);
		}
		usleep(10000);
	}
	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;

}
#endif

int disp_jpeg_center_1(char *filename)
{	
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;

	for(i = 0; i < my_fb.w; i++)
	{
		for(j = 0; j < my_fb.h / 4; j++)
		{
			fb_pixel(i, j, buf32[i + j * my_fb.w]);
			fb_pixel(my_fb.w - i, j + my_fb.h / 4, buf32[my_fb.w - i + (j +my_fb.h / 4) * my_fb.w]);
			fb_pixel(i, j + my_fb.h / 2, buf32[i + (j + my_fb.h / 2) * my_fb.w]);
			fb_pixel(my_fb.w - i, j + (3 * my_fb.h) / 4, buf32[my_fb.w - i + (j + (3 * my_fb.h) / 4) * my_fb.w]);
		}
		usleep(10000);
	}
	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;
}

int disp_jpeg_center_2(char *filename)
{
	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;

	for(j = 0; j < my_fb.h; j++)
	{
		for(i = 0; i < my_fb.w / 4; i++)
		{
			fb_pixel(i, j, buf32[i + j * my_fb.w]);
			fb_pixel(my_fb.w / 2 - i - 1, my_fb.h - j - 1, buf32[my_fb.w / 2 - i - 1 + (my_fb.h - j - 1) * my_fb.w]);		
			fb_pixel(my_fb.w / 2 + i, j, buf32[my_fb.w / 2 + i + j * my_fb.w]);
			fb_pixel(i + (3 *  my_fb.w) / 4, my_fb.h - j - 1, buf32[(3 * my_fb.w) / 4 + i + (my_fb.h - j - 1) * my_fb.w]);

		}
		usleep(10000);
	}
	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);

	return 0;

}

int disp_jpeg_style1(char *filename)
{

	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;

	for(j = 0; j < my_fb.w; j++)
	{
		for(i = 0; i < my_fb.h / 2; i++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w - j, i + my_fb.h / 2, buf32[my_fb.w - j + (i + my_fb.h / 2) * my_fb.w]);
		}
		usleep(10000);
	}
	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}


int disp_jpeg_style2(char *filename)
{

	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;

	for(j = 0; j < my_fb.w / 2; j++)
	{
		for(i = 0; i < my_fb.h / 2; i++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w - j, i + my_fb.h / 2, buf32[my_fb.w - j + (i + my_fb.h / 2) * my_fb.w]);
			fb_pixel(j + my_fb.w / 2, i, buf32[(j + my_fb.w / 2) + i * my_fb.w]);
			fb_pixel(my_fb.w / 2 - j, i + my_fb.h / 2, buf32[(my_fb.w / 2 - j) + (i + my_fb.h / 2) * my_fb.w]);
		}

		usleep(10000);
	}

	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}

int disp_jpeg_style3(char *filename)
{

	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;

	for(j = 0; j <= my_fb.w / 2; j++)
	{
		for(i = 0; i < my_fb.h / 2; i++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w - j, i + my_fb.h / 2, buf32[my_fb.w - j + (i + my_fb.h / 2) * my_fb.w]);
		}
		usleep(10000);
	}
	for(i = my_fb.h / 2; i < my_fb.h; i++)
	{
		for(j = 0; j < my_fb.w / 2; j++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w / 2 + j, my_fb.h - i, buf32[(j + my_fb.w / 2) + (my_fb.h - i) * my_fb.w]);
		}	
		usleep(10000);

	}
	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}

int disp_jpeg_style4(char *filename)
{

	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;
#if 1
	for(i = my_fb.h / 2; i < my_fb.h; i++)
	{
		for(j = 0; j < my_fb.w / 2; j++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w / 2 + j, my_fb.h - i, buf32[(j + my_fb.w / 2) + (my_fb.h - i) * my_fb.w]);
		}	
		usleep(10000);

	}
#endif

#if 1
	for(j = 0; j <= my_fb.w / 2; j++)
	{
		for(i = 0; i < my_fb.h / 2; i++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w - j, i + my_fb.h / 2, buf32[my_fb.w - j + (i + my_fb.h / 2) * my_fb.w]);
		}
		usleep(10000);
	}
#endif
	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}

#endif

int disp_jpeg_style5(char *filename)
{

	fb_info jpeg_inf;

	u8_t *buf24 = decode_jpeg(filename, &jpeg_inf);
	u8_t *scale_buf = scale24(buf24, my_fb, jpeg_inf);
	u32_t *buf32 = rgb24to32(scale_buf, my_fb);

	int i = 0;
	int j = 0;
#if 1
	for(i = my_fb.h / 2; i < my_fb.h; i++)
	{
		for(j = 0; j < my_fb.w / 2; j++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w / 2 + j, my_fb.h - i, buf32[(j + my_fb.w / 2) + (my_fb.h - i) * my_fb.w]);
		}	
		usleep(10000);

	}
#endif

#if 1
	for(j = my_fb.w / 2; j > 0; j--)
	{
		for(i = 0; i < my_fb.h / 2; i++)
		{
			fb_pixel(j, i, buf32[j + i * my_fb.w]);
			fb_pixel(my_fb.w - j, i + my_fb.h / 2, buf32[my_fb.w - j + (i + my_fb.h / 2) * my_fb.w]);
		}
		usleep(10000);
	}
#endif
	usleep(500000);
	printf("i = %d j = %d\n", i, j);
	free(buf24);
	free(scale_buf);
	free(buf32);
	return 0;
}
